package ar.edu.itba.it.paw.web.base;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import ar.edu.itba.it.paw.domain.Category;
import ar.edu.itba.it.paw.domain.EntityModel;
import ar.edu.itba.it.paw.domain.User;
import ar.edu.itba.it.paw.web.MercadoLibre;
import ar.edu.itba.it.paw.web.MercadoLibreSession;
import ar.edu.itba.it.paw.web.product.OrderProductPage;
import ar.edu.itba.it.paw.web.user.RegisterUserPage;
import ar.edu.itba.it.paw.web.user.UserMenuPage;



public class BasePage extends WebPage {

	public BasePage() {
		
		IModel<User> userModel = new EntityModel<User>(User.class,MercadoLibreSession.get().getUser());
 		
		if(MercadoLibreSession.get().getUser()== null){
			add(new Label("username",""));
		}else{
			add(new Label("username", new PropertyModel<User>(userModel, "username")));
		}
		add(new Image("mainImage", MercadoLibre.MAIN_ICON));
		add(new Link<Void>("index") {
			@Override
			public void onClick() {
				if(MercadoLibreSession.get().getUser() == null){
					System.out.println("no user a ppal");
					setResponsePage(getApplication().getHomePage());
				}else{
					System.out.println("si user a donde estoy");
					setResponsePage(UserMenuPage.class);
				}
			}
		});
		Link<Void> register_link = new Link<Void>("register") {
			@Override
			public void onClick() {
				setResponsePage(RegisterUserPage.class);
			}
		};
		if(MercadoLibreSession.get().getUser() != null){
			register_link.setVisibilityAllowed(false);
		}
		add(register_link);
		add(new Link<Void>("orderProducts") {
			@Override
			public void onClick() {
				//TODO: como parametro debe pasarse la clase que muestre la pag de ordenamiento
				setResponsePage(new OrderProductPage(new Category(0,"Todos"),"nombre","asc"));
			}
		});
		add(new Link<Void>("mailto") {
			@Override
			public void onClick() {
				//TODO: esto tengo que preguntar como se hace para el link
				setResponsePage(getApplication().getHomePage());
			}
		});
		add(new Link<Void>("header") {
			@Override
			public void onClick() {
				//TODO: Es feo preguntar como mejorar
				setResponsePage(getApplication().getHomePage());
			}
		});
	}
}
